<style lang="scss" scoped>
	.content {
		width: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.box {
		width: 690rpx;
		padding: 30rpx 20rpx;
		background: #ffffff;
		border-radius: 20rpx;
		box-shadow: 0rpx 32rpx 20rpx -20rpx #e6ebf2;
		margin-top: 30rpx;

		.line {
			width: 100%;
			height: 100rpx;
			border-top: 1px solid #eeeeee;

			.ipt {
				width: 500rpx;
				text-align: right;
			}
		}

		.line2 {
			width: 100%;
			border-top: 1px solid #eeeeee;
			align-items: flex-start;

			.des {
				width: 500rpx;
				text-align: justify;
			}
		}

		.line3 {
			height: 100rpx;

			>view {
				width: 50%;
			}
		}

		.sbtn {
			width: 184rpx;
			height: 64rpx;
			background: #fffefe;
			border: 2rpx solid #409eff;
			border-radius: 34rpx;
		}

		.imgboxs {
			width: 100%;
			flex-wrap: wrap;

			.imgbox {
				width: 148rpx;
				height: 148rpx;
				border: 2rpx solid #dee2ee;
				border-radius: 10rpx;
				position: relative;
				margin-right: 18rpx;

				.photo {
					width: 100%;
					height: 100%;

				}

				.close {
					position: absolute;
					width: 32rpx;
					height: 32rpx;
					right: -16rpx;
					top: -16rpx;
				}
			}

			.imgbox:nth-child(4n) {

				margin-right: 0rpx;
			}
		}
	}

	.lbtn2 {
		margin: 60rpx auto;
		width: 690rpx;
		height: 88rpx;
		background: #ffffff;
		border: 2rpx solid #409eff;
		border-radius: 46rpx;
		box-shadow: 0rpx 32rpx 20rpx -20rpx #e6ebf2;
		color: #409eff;
	}

	.tip {
		color: #98A5B3;
		padding: 0 60rpx;
		width: 100%;
	}

	.btns {
		width: 100%;
		height: 100rpx;
		border-top: 2rpx solid #f5f7fa;

		.btn {
			width: 50%;
			height: 100rpx;
			border-right: 2rpx solid #f5f7fa;

			>image {
				width: 38rpx;
				height: 38rpx;
				margin-right: 10rpx;
			}
		}
	}

	.footer {
		width: 100%;
		background-color: white;
		position: fixed;
		bottom: 0;
		left: 0;
		border-top: 1px solid #cccccc;
		padding-left: 30rpx;
		padding-right: 30rpx;
		z-index: 100;

		.sbtn {
			width: 176rpx;
			height: 88rpx;
			border: 2rpx solid #dee2ee;
			border-radius: 46rpx;
		}

		.lbtn {
			width: 484rpx;
			margin-right: 0;
		}
	}
</style>

<template>
	<view class="content">
		<view class="tip between-flex m-top30 f28">
			<view>创建人:{{user}}</view>
			<view>创建时间: {{date/1000 | alltime}}</view>
		</view>
		<view class="box p-bottom30">
			<view class="f32 bold textColor p-bottom30">会议纪要</view>
			<view class="line between-flex f28">
				<view class="gray">记录人</view>
				<view class="textColor">{{$getNames(info.hosts)}}</view>
			</view>
			<view class="line between-flex f28">
				<view class="gray">到会人员</view>
				<view class="blue align-flex"
					@click="!person?$navTo(PagesCourseRouterConfig.ChoosePerson): $navTo(PagesCourseRouterConfig.ChoosePerson+'?users='+person.value)">
					<span v-if="!person">请选择</span>
					<span v-else class=" align-flex">
						<view style="max-width:370rpx;" class="one">{{person.value | users}}</view>
						等{{person.value.split(',').length}}人
					</span>
					<u-icon name='arrow-right'></u-icon>
				</view>
			</view>
			<view class="line2 between-flex f28 p-top20">
				<view class="gray">会议纪要</view>
				<textarea class="des textColor" v-model="info.summary" placeholder="请填写" style="height:100rpx;" />

			</view>
		</view>
		<view class="box">
			<view class="f32 bold textColor">任务</view>
		</view>
		<view class="box" style="padding-bottom: 0;" v-for="item,index in task" :key="index">
			<view class="textColor f28 bold">{{index+1}}. {{item.taskName}}</view>
			<view class="between-flex line3">
				<view class="align-flex">
					<view class="gray m-right20">责任人</view><span class="textColor">{{item.leaderUser | user}}</span>
				</view>
				<view class="align-flex">
					<view class="gray m-right20">结束时间</view><span
						class="textColor">{{item.planEndDate?item.planEndDate:'-'}}</span>
				</view>
			</view>
			<view class="btns between-flex gray f24">
				<view class="btn center-flex" @click="delTask(item,index)">
					<image src="../../static/images/del.png" mode="aspectFit"></image> 删除
				</view>
				<view class="btn center-flex blue" style="border-right: none;"
					@click="$navTo(PagesHuiYiRouterConfig.Add+'?id='+item.id)">
					<image src="../../static/images/edit.png" mode="aspectFit"></image> 编辑
				</view>
			</view>
		</view>

		<view class="lbtn blue lbtn2" @click="$navTo(PagesHuiYiRouterConfig.Add)">添加任务</view>
		<view class="space"></view>
		<view class="footer between-flex paddingBottom">
			<view class="sbtn center-flex textColor bold f32" @click="$back">取消</view>
			<view class="lbtn" @click="submit(2)">保存</view>
		</view>
	</view>
</template>

<script>
	import PagesCourseRouterConfig from '@/pagesCourse/routerConfig.js'
		import PagesHuiYiRouterConfig from  '@/pagesHuiyi/routerConfig.js'
	export default {
		data() {
			return {
				PagesCourseRouterConfig,
				PagesHuiYiRouterConfig,
				user: uni.getStorageSync('username'),
				date: new Date().getTime(),
				head: this.$head,
				id: '',
				info: {},
				person: null,
				task: [],


			}
		},
		onLoad(e) {
			this.id = e.id
			this.getInfo()
			uni.$on('addTask', data => {
				this.task.push(data)
				this.submit(1)
			})
			uni.$on('editTask', data => {
				this.task=[]
				this.getInfo()
			})
		},
		beforeDestroy() {
			uni.$off('addTask')
			uni.$off('editTask')
		},
		methods: {
			delTask(item,index){
				uni.showModal({
					title: '确认删除该任务吗？',
					success: (res) => {
						if (res.confirm) {
							this.$pop.ajaxPost('/bus/taskInfo/del', {
								id: item.id
							}).then(res => {
								if (res.code == 0) {
									
									this.task.splice(index,1)
									this.submit(1)
								} else {
									this.$msg(res.msg)
								}
							})
						}
					}
				})
			},
			
			submit(type) {
				var meetingUsers = []
				if (this.person) {
					let person = this.person.value.split(',')
					person.forEach(item => {
						meetingUsers.push({
							type: 4,
							user: item
						})
					})

				}
				var taskId = []
				this.task.forEach(item => {
					taskId.push(item.id)
				})
				this.$showloading()


				this.$pop.ajaxPost('/bus/weChatMeeting/saveOrUpdateSummary', {
					id: this.id,
					summary: this.info.summary,
					meetingUsers: JSON.stringify(meetingUsers),
					taskId: taskId.length > 0 ? taskId.join(',') : ''
				}).then((res) => {
					uni.hideLoading()
					if (res.code == 0) {

						this.$msg(res.msg)
						if(type==2){
							setTimeout(()=>{
								uni.navigateBack({
									
								})
							},1500)
						}
						
					} else {
						this.$msg(res.msg)
					}
				})
			},
			getInfo() {
				this.$pop.ajaxPost('/bus/busMeeting/getById', {
					id: this.id
				}).then(res => {
					this.info = res.body
					var addperson = []
					if (this.info.users.length > 0) {
						addperson = this.info.users
					} else if (this.info.attends) {
						addperson = this.info.attends
					}
					var name = []
					var value = []
					addperson.forEach(item => {
						name.push(item.userName)
						value.push(item.user)
					})
					if (name.length > 0) {
						this.person = {
							name: name.join(','),
							value: value.join(',')
						}
					}
					if (this.info.taskId) { //有任务
						this.getTask()
					}
				})
			},
			getTask() {
				var ids = this.info.taskId
				ids = ids.split(',')
				ids.forEach(item=>{
					this.$pop.ajaxPost('/bus/taskInfo/details', {
						id: item
					}).then(res=>{
						this.task.push(res.body)
					})
				})
			}

		}
	}
</script>
